home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 281_01 / window.c < prev    next >
C/C++ Source or Header  |  1988-10-05  |  24KB  |  839 lines

  1. /*  window.c
  2.  *
  3.  *  Demo program for uclib.lib Version 5.10
  4.  *
  5.  */
  6.  
  7. /*--------------------------------------------------------------------*/
  8. /*  This program in no way illustrates each of the over 300 functions */
  9. /*  contained in uclib.lib version 5.10.  It does however make an     */
  10. /*  attempt to illustrate some of what can be done with the library.  */
  11. /*--------------------------------------------------------------------*/
  12.  
  13. #include <stdio.h>       /* needed since NULL is used in uc_defs.h  */
  14. #ifdef MSC
  15. #include <malloc.h>
  16. #else
  17. #include <alloc.h>
  18. #endif
  19.  
  20. #include "uc_defs.h"       /* Assume the headers are in the current   */
  21. #include "uc_glob.h"       /* directory.                  */
  22. #include "uc_proto.h"
  23.  
  24. #include "wn_defs.h"
  25. #include "wn_glob.h"
  26. #include "wn_proto.h"
  27.  
  28. extern WINDOWPTR  err_wnd; /* Allow access to the system error window */
  29.  
  30. void main( void )       /* Unicorn Software programs are written   */
  31. {               /* using ANSI standard prototyping.          */
  32.    WINDOWPTR    wn_main;
  33.    WINDOWPTR    wn_sub;    /* sub window for the main screen window   */
  34.    WINDOWPTR    wn_1;
  35.    WINDOWPTR    wn_2;
  36.    WINDOWPTR    wn_3;
  37.    WINDOWPTR    wn_4;
  38.    WINDOWPTR    wn_5;
  39.    WINDOWPTR    wn_6;
  40.    WINDOWPTR    wn_7;
  41.    WINDOWPTR    wn_8;
  42.    WINDOWPTR    wn_9;
  43.    WINDOWPTR    wn_10;
  44.  
  45.    char     *str_save();
  46.  
  47.    char     err_str[ 256 ];  /* error message string          */
  48.    int        i;
  49.    int        count;
  50.  
  51.  
  52.    uc_init();             /* Inititalize various system values */
  53.    if ( mouse_exist )
  54.       m_flagdec();
  55.  
  56.    cur_off();              /* Turn off the cursor to avoid clutter */
  57.  
  58.    wn_main = wn_make( 0, 0, 25, 80 );  /* Define a window and size it */
  59.                   /* Set the window normal attribute      */
  60.    wn_wnclr( wn_main, mk_att( BLUE, BROWN + BRIGHT ) );
  61.                   /* Set the window border attribute      */
  62.    wn_bclr( wn_main, mk_att( BLUE, WHITE + BRIGHT ) );
  63.    wn_clear( wn_main );       /* Clear the window area              */
  64.  
  65.                   /* Set up a window title - a future     */
  66.                   /* enhancement will allow more than one */
  67.                   /* title to be placed in the window's   */
  68.                   /* border.  Position parameters will    */
  69.                   /* also be allowed such as CENTER etc.  */
  70.                   /* Also functions will be added to set  */
  71.                   /* up the title directly without going  */
  72.                   /* through this indirect process.       */
  73.  
  74.    wn_main->title = ( TITLEPTR ) malloc( sizeof( TITLE ) );
  75.  
  76.  
  77.    wn_main->title->title = ( char * ) malloc( 100 );
  78.  
  79.  
  80.    strcpy( wn_main->title->title,
  81. " Unicorn Software P.O. Box 3214 Kirkland, WA 98034-3214 (206) 823-4656" );
  82.    wn_main->title->position = 4;
  83.                     /* Set the title color          */
  84.    wn_main->clr->title = mk_att( WHITE, RED + BRIGHT );
  85.  
  86.                   /* Set the window's right & left margins*/
  87.    wn_margin( wn_main, 3 );
  88.  
  89.    wn_mkbdr( wn_main, BDR_DLNP ); /* make a border for the window     */
  90.  
  91.  
  92.  
  93.  
  94.    wn_sub = wn_make( 4, 5, 19, 72 );  /* Define a window and size it */
  95.                   /* Set the window normal attribute      */
  96.    wn_wnclr( wn_sub, mk_att( BLUE, BROWN + BRIGHT ) );
  97.                   /* Set the window border attribute      */
  98.    wn_bclr( wn_sub, mk_att( BLUE, WHITE + BRIGHT ) );
  99.    wn_clear( wn_sub );          /* Clear the window area              */
  100.  
  101.    wn_margin( wn_sub, 1 );
  102.  
  103.    wn_mkbdr( wn_sub, BDR_SLNP );  /* make a border for the window     */
  104.  
  105.  
  106.  
  107. /*--------------------------------------------------------------------*/
  108. /* At this point the window has been defined and all parameters for   */
  109. /* the basic window, the title and border are contained in structures.*/
  110. /* Next we will write some text to the window, even though it is not  */
  111. /* yet displayed on the screen, then the window will be displayed and */
  112. /* finally further text will be written to the displayed window.      */
  113. /*--------------------------------------------------------------------*/
  114.  
  115.                  /* the following function writes a single*/
  116.                  /* character to the window.          */
  117.    wn_pchar( wn_main, '\n' );
  118.  
  119.    for ( i = 0; i <= 25; i++ )
  120.       wn_pchar( wn_main, ' ' );
  121.  
  122.    wn_pchar( wn_main, 'U' );
  123.    wn_pchar( wn_main, 'n' );
  124.    wn_pchar( wn_main, 'i' );
  125.    wn_pchar( wn_main, 'c' );
  126.    wn_pchar( wn_main, 'o' );
  127.    wn_pchar( wn_main, 'r' );
  128.    wn_pchar( wn_main, 'n' );
  129.    wn_pchar( wn_main, ' ' );
  130.    wn_pchar( wn_main, 'L' );
  131.    wn_pchar( wn_main, 'i' );
  132.    wn_pchar( wn_main, 'b' );
  133.    wn_pchar( wn_main, 'r' );
  134.    wn_pchar( wn_main, 'a' );
  135.    wn_pchar( wn_main, 'r' );
  136.    wn_pchar( wn_main, 'y' );
  137.    wn_pchar( wn_main, ' ' );
  138.    wn_pchar( wn_main, '5' );
  139.    wn_pchar( wn_main, '.' );
  140.    wn_pchar( wn_main, '0' );
  141.    wn_pchar( wn_main, '0' );
  142.    wn_pchar( wn_main, '\n' );
  143.    wn_pchar( wn_main, '\n' );
  144.  
  145.  
  146.    wn_wnclr( wn_sub, mk_att( BLUE, WHITE ) );
  147.  
  148.    wn_printf( wn_sub,
  149.    "\nWelcome to version 5.10 of " );
  150.  
  151.    wn_wnclr( wn_sub, mk_att( BLUE, CYAN + BRIGHT ) );
  152.  
  153.    wn_printf( wn_sub,
  154.    "UCLIB.LIB" );
  155.  
  156.    wn_wnclr( wn_sub, mk_att( BLUE, WHITE ) );
  157.  
  158.    wn_printf( wn_sub,
  159.    ".  This all new version of\n" );
  160.  
  161.    wn_printf( wn_sub,
  162.    "the library contains many differences from past releases.  First\n" );
  163.  
  164.    wn_printf( wn_sub,
  165.    "and foremost the library is now entirely in C, gone are the \n" );
  166.  
  167.    wn_printf( wn_sub,
  168.    "assembler routines of past releases.  This should make it much\n" );
  169.  
  170.    wn_printf( wn_sub,
  171.    "easier for users to understand and work with the library source\n" );
  172.  
  173.    wn_printf( wn_sub,
  174.    "code.  An " );
  175.  
  176.    wn_wnclr( wn_sub, mk_att( BLUE, WHITE + BRIGHT ) );
  177.  
  178.    wn_printf( wn_sub,
  179.    "all new windowing package " );
  180.  
  181.    wn_wnclr( wn_sub, mk_att( BLUE, WHITE ) );
  182.  
  183.    wn_printf( wn_sub,
  184.    " is included as is the " );
  185.  
  186.    wn_wnclr( wn_sub, mk_att( BLUE, WHITE + BRIGHT ) );
  187.  
  188.    wn_printf( wn_sub,
  189.    "data\nentry system" );
  190.  
  191.    wn_wnclr( wn_sub, mk_att( BLUE, WHITE ) );
  192.  
  193.    wn_printf( wn_sub,
  194.    ".  The new windowing system allows you to write to\n" );
  195.  
  196.    wn_printf( wn_sub,
  197.    "a window whether or not it is currently displayed on the screen.\n" );
  198.  
  199.    wn_printf( wn_sub,
  200.    "The data entry system uses this windowing system for maximum user\n" );
  201.  
  202.    wn_printf( wn_sub,
  203.    "flexibility.  As this demo progresses it will stop at various points.\n" );
  204.  
  205.    wn_printf( wn_sub,
  206.    "When this occurs simply press a key to continue.                       \n" );
  207.  
  208.    wn_printf( wn_sub,
  209.    "          \n" );
  210.  
  211.    wn_dsply( wn_main );
  212.  
  213.    wn_dsply( wn_sub );     /* display the window now!!             */
  214.  
  215.  
  216.    gr_bckgnd( BLUE );      /* Set the border color              */
  217.  
  218.  
  219.    uc_key();   /* get a user key stroke and ignore the key returned   */
  220.  
  221.  
  222.    wn_printf( wn_sub,
  223.    "\nSee how simple that was!  Now in this section please note\n" );
  224.  
  225.    wn_printf( wn_sub,
  226.    "two important items, first the cursor has been turned off to\n" );
  227.  
  228.    wn_printf( wn_sub,
  229.    "avoid unsightly screen clutter and secondly the main text of\n" );
  230.  
  231.    wn_printf( wn_sub,
  232.    "this window will scroll as new lines are added.               \n" );
  233.  
  234.    uc_key();
  235.  
  236.    wn_printf( wn_sub,
  237.    "\nIn this next section additional windows will be placed on the\n" );
  238.  
  239.    wn_printf( wn_sub,
  240.    "screen.  They will be moved in all three directions, text will\n" );
  241.  
  242.    wn_printf( wn_sub,
  243.    "be written to them in addition to other suprises.             \n" );
  244.  
  245.  
  246.    uc_key();
  247.  
  248.  
  249.  
  250.    wn_1 = wn_make( 5, 5, 12, 40 );
  251.    wn_wnclr( wn_1, mk_att( RED, BROWN + BRIGHT ) );
  252.    wn_bclr( wn_1, mk_att( RED, WHITE + BRIGHT ) );
  253.    wn_clear( wn_1 );
  254.    wn_1->title = ( TITLEPTR ) malloc( sizeof( TITLE ) );
  255.    wn_1->title->title = ( char * ) malloc( 100 );
  256.    strcpy( wn_1->title->title, " Sub Window 1 " );
  257.    wn_1->title->position = 4;
  258.    wn_1->clr->title = mk_att( RED, WHITE + BRIGHT );
  259.    wn_margin( wn_1, 1 );
  260.    wn_mkbdr( wn_1, BDR_12LNP );
  261.  
  262.  
  263.    wn_dsply( wn_1 );
  264.  
  265.    wn_printf( wn_1, "This window is currently in the\n" );
  266.  
  267.    wn_printf( wn_1, "forefront and next another window\n" );
  268.  
  269.    wn_printf( wn_1, "will be placed on the screen which\n" );
  270.  
  271.    wn_printf( wn_1, "will partially obscure this one.\n" );
  272.  
  273.    uc_key();
  274.  
  275.  
  276.  
  277.  
  278.    w